import {createApp} from 'vue'
import App from './App.vue'
// 自定义css
import './assets/main.css'
//阿里icon
import './assets/css/icon/iconfont.css'
//中文阅读的网页排版 typo.css
import "./assets/css/typo.css";
//semantic-ui-vue
import SuiVue from 'semantic-ui-vue'
import 'semantic-ui-css/semantic.min.css'
// element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//moment
import './util/dateTimeFormatUtils.js'
//图片浏览组件 v-viewer
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
import router from "@/router";
import dateTimeFormatUtils from "@/util/dateTimeFormatUtils";
import directive from "@/util/directive";
import store from "@/store";

const app = createApp(App);
app.use(ElementPlus)
    .use(SuiVue)
    .use(Viewer, {
        defaultOptions: {
            zIndex: 9999,
            toolbar: true,
            transition: false,
            title: false,
            navbar: true,
            // button:false,
            scalable: true,
            rotatable: true,
            tooltip: true,
            inline: true,
        }
    })
    .use(router)
    .use(dateTimeFormatUtils)
    .use(directive)
    .use(store)

app.config.globalProperties.msgSuccess = function (msg) {
    this.$message.success(msg)
}

app.config.globalProperties.msgError = function (msg) {
    this.$message.error(msg)
}

app.config.globalProperties.msgInfo = function (msg) {
    this.$message.info(msg);
}

const cubic = value => Math.pow(value, 3);
const easeInOutCubic = value => value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2;
//滚动至页面顶部，使用 Element-ui 回到顶部 组件中的算法
app.config.globalProperties.scrollToTop = function () {
    const el = document.documentElement
    const beginTime = Date.now()
    const beginValue = el.scrollTop
    const rAF = window.requestAnimationFrame || (func => setTimeout(func, 16))
    const frameFunc = () => {
        const progress = (Date.now() - beginTime) / 500;
        if (progress < 1) {
            el.scrollTop = beginValue * (1 - easeInOutCubic(progress))
            rAF(frameFunc)
        } else {
            el.scrollTop = 0 //500毫秒执行完毕
        }
    }
    rAF(frameFunc)
}

app.mount('#app')
